package meituan;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Random;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        second();
    }
    static class Score{
        int id;
        double p;
        double a;
        double value;
        public Score(int id,double p,double a){
            this.id=id;
            this.p=p;
            this.a=a;
            this.value=a/p;
        }
    }
    public static void second(){

        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        Score[] scores=new Score[n*2];
        for (int i = 0; i < n; i++) {
            scores[i*2]=new Score(i,sc.nextDouble(),sc.nextDouble());
            scores[i*2+1]=new Score(i,sc.nextDouble(),sc.nextDouble());
        }
        Arrays.sort(scores,(a,b)->(a.a-b.a==0?0:(a.a-b.a>0?-1:1)));


        Random r=new Random(10);
        int res=0;
        for (int i = 0; i < 1000; i++) {
            int result=0;
            int time=0;
            HashSet<Integer> set=new HashSet<>(n);
            for (Score score : scores) {
                if(score.p+time<=120&& r.nextInt(10)>1  &&set.add(score.id)){
                    time+=score.p;
                    result+=score.a;
                }
            }
            res=Math.max(res,result);
        }

        System.out.println(res);

    }
}
/*
4
20 20 100 60
50 30 80 55
100 60 110 88
5 3 10 6
 */
//